﻿using System;
using System.Drawing;
using System.Text;

namespace WebsiteUI.Extensions
{
    public class RandNumSupplier
    {
        private const string BASECODE = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
        private const string BASECODE_REGIST = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789上中下左右大小多少人口手山石田土禾木水火东令车甲由申八白百可不贝女山用天";
        private static Color[] colors = new Color[] { Color.Black, Color.Blue, Color.Green, Color.Red, Color.Purple };
        private static Random rnd = new Random((int)DateTime.Now.Ticks);

        public static string GetRandomCode(int length)
        {
            StringBuilder code = new StringBuilder(length);
            for (int i = 0; i < length; i++)
            {
                int rndNum = rnd.Next(BASECODE.Length);
                code.Append(BASECODE[rndNum]);
            }
            return code.ToString();
        }

        /// <summary>
        /// 注册所用的验证码
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetRandomCodeReg(int length)
        {
            StringBuilder code = new StringBuilder(length);
            for (int i = 0; i < length; i++)
            {
                int rndNum = rnd.Next(BASECODE_REGIST.Length);
                code.Append(BASECODE_REGIST[rndNum]);
            }
            return code.ToString();
        }


        public static Color GetRandomColor()
        {
            return colors[rnd.Next(colors.Length)];
        }
    }
}